package com.googlecode.fxutils;

/*
Copyright (c) 2014, Carlos Eduardo Klock.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import javafx.stage.Window;

/**
 * Properties for popup windows. These properties are used to initialize the popups.
 * @see PopupUtils
 */
public class PopupProperties {

    private Window ownerWindow = null;
    private boolean autoFix = true;
    private boolean autoHide = true;
    private boolean hideOnEscape = true;
    private boolean centralizeOnOwner = true;
    private String inlineStyle = null;
    private double x = 0;
    private double y = 0;

    public PopupProperties() {
    }

    public PopupProperties(Window ownerWindow) {
        if (ownerWindow == null) {
            throw new NullPointerException("Owner window can't be null!");
        }
        this.ownerWindow = ownerWindow;
    }
    
    /**
     * Convenience method to create common properties/style for popups.
     * @param owner              defines the owner window.
     * @param centralizeOnOwner  defines if the popup will be centralized on the owner when displayed.
     * @param backgroundColor    background color of the popup.
     * @param fontSize           font size of the message.
     * @param borderColor        color of the border.
     * @param padding            internal padding.
     * @return the properties.
     */
    public static PopupProperties createMessageStyleProperties(final Window owner, boolean centralizeOnOwner, String backgroundColor, int fontSize, String borderColor, int padding) {
        PopupProperties properties = new PopupProperties(owner);
        properties.setInlineStyle(String.format("-fx-background-color:%s; -fx-font-size:%s; -fx-border-color:%s; -fx-padding:%s; ", backgroundColor, fontSize, borderColor, padding));
        properties.setCentralizeOnOwner(centralizeOnOwner);
        return properties;
    }
    
    /**
     * Convenience method to create common properties/style for popups.
     * @param owner              defines the owner window.
     * @param centralizeOnOwner  defines if the popup will be centralized on the owner when displayed.
     * @return the properties.
     */
    public static PopupProperties createMessageStyleProperties(final Window owner, boolean centralizeOnOwner) {
        return createMessageStyleProperties(owner, centralizeOnOwner, "cornsilk", 16, "black", 10);
    }
    
    /**
     * Convenience method to create common properties/style for popups.
     * @param owner              defines the owner window.
     * @param backgroundColor    background color of the popup.
     * @param borderColor        color of the border.
     * @return the properties.
     */
    public static PopupProperties createContentStyleProperties(final Window owner, String backgroundColor, String borderColor) {
        PopupProperties properties = new PopupProperties(owner);
        properties.setInlineStyle(String.format("-fx-background-color:%s; -fx-border-color:%s;", backgroundColor, borderColor));
        properties.setCentralizeOnOwner(true);
        return properties;
    }
    
    /**
     * Convenience method to create common properties/style for popups.
     * @param owner              defines the owner window.
     * @return the properties.
     */
    public static PopupProperties createContentStyleProperties(final Window owner) {
        return createContentStyleProperties(owner, "white", "black");
    }

    public Window getOwnerWindow() {
        if (ownerWindow == null) {
            throw new NullPointerException("Owner window must be defined!");
        }
        return ownerWindow;
    }

    public PopupProperties setOwnerWindow(Window ownerWindow) {
        if (ownerWindow == null) {
            throw new NullPointerException("Owner window can't be null!");
        }
        this.ownerWindow = ownerWindow;
        return this;
    }

    public boolean isAutoFix() {
        return autoFix;
    }

    public PopupProperties setAutoFix(boolean autoFix) {
        this.autoFix = autoFix;
        return this;
    }

    public boolean isAutoHide() {
        return autoHide;
    }

    public PopupProperties setAutoHide(boolean autoHide) {
        this.autoHide = autoHide;
        return this;
    }

    public boolean isHideOnEscape() {
        return hideOnEscape;
    }

    public PopupProperties setHideOnEscape(boolean hideOnEscape) {
        this.hideOnEscape = hideOnEscape;
        return this;
    }

    public boolean isCentralizeOnOwner() {
        return centralizeOnOwner;
    }

    public PopupProperties setCentralizeOnOwner(boolean centralizeOnOwner) {
        this.centralizeOnOwner = centralizeOnOwner;
        return this;
    }

    public String getInlineStyle() {
        return inlineStyle;
    }

    public PopupProperties setInlineStyle(String inlineStyle) {
        this.inlineStyle = inlineStyle;
        return this;
    }

    public double getX() {
        return x;
    }

    public PopupProperties setX(double x) {
        this.x = x;
        return this;
    }

    public double getY() {
        return y;
    }

    public PopupProperties setY(double y) {
        this.y = y;
        return this;
    }
    
}
